/**
 * Copyright 2007 Luke Pillow
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.orsomethinglikethat.flex.filemaker
{
	import mx.utils.Base64Encoder;
	import flash.net.URLRequest;
	import com.orsomethinglikethat.flex.filemaker.command.FindAnyCommand;
	import flash.net.URLRequestHeader;
	import flash.net.URLRequestMethod;
	import mx.controls.Alert;
	import com.orsomethinglikethat.flex.filemaker.command.FindAllCommand;
	import com.orsomethinglikethat.flex.filemaker.command.FindCommand;
	
	/**
	 * Base FileMaker class
	 */
	public class FileMaker
	{
		public var serverUrl:String;
		public var database:String;
		public var credentials:String;
		
		public function FileMaker( serverUrl:String, database:String, username:String, password:String )
		{
			super();
			
			this.serverUrl = serverUrl;
			this.database = database;
			this.credentials = this.buildCredentials( username, password );
		}
		
		private function buildCredentials( username:String, password:String ):String
		{
			var encoder:Base64Encoder = new Base64Encoder();
			encoder.encode( username + ":" + password );
			
			return encoder.flush();
		}
		
		public function newFindCommand( layout:String ):FindCommand
		{
			return new FindCommand( this, layout );
		}
		
		public function newFindAnyCommand( layout:String ):FindAnyCommand
		{
			return new FindAnyCommand( this, layout );
		}
		
		public function newFindAllCommand( layout:String ):FindAllCommand
		{
			return new FindAllCommand( this, layout );
		}
	}
}